package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20250303153232CreateSystemConfigTables struct {
}

// Signature The unique signature for the migration.
func (r *M20250303153232CreateSystemConfigTables) Signature() string {
	return "20250303153232_create_system_config_tables"
}

// Up Run the migrations.
func (r *M20250303153232CreateSystemConfigTables) Up() error {
	if !facades.Schema().HasTable("system_config_tables") {
		facades.Schema().Create("system_config_tables", func(table schema.Blueprint) {
			table.ID()
			table.String("field_name")
			table.String("field_type").Default("")
			table.String("input_type").Default("input")
			table.UnsignedBigInteger("system_config_tab_id").Default(0)
			table.String("parameter").Default("")
			table.SmallInteger("upload_type").Default(1)
			table.String("required").Default("")
			table.Integer("width")
			table.Integer("height")
			table.Text("value").Comment("设置值，或者默认值")
			table.String("info").Default("")
			table.String("description").Default("")
			table.Integer("sort").Default(0)
			table.SmallInteger("hidden").Default(0)
			table.SmallInteger("level").Default(0)
			table.Timestamps()
		})
	}
	if !facades.Schema().Connection("school").HasTable("system_config_tables") {
		facades.Schema().Connection("school").Create("system_config_tables", func(table schema.Blueprint) {
			table.ID()
			table.String("field_name")
			table.String("field_type").Default("")
			table.String("input_type").Default("input")
			table.UnsignedBigInteger("system_config_tab_id").Default(0)
			table.String("parameter").Default("")
			table.SmallInteger("upload_type").Default(1)
			table.String("required").Default("")
			table.Integer("width")
			table.Integer("height")
			table.Text("value").Comment("设置值，或者默认值")
			table.String("info").Default("")
			table.String("description").Default("")
			table.Integer("sort").Default(0)
			table.SmallInteger("hidden").Default(0)
			table.SmallInteger("level").Default(0)
			table.Timestamps()
		})
	}
	if !facades.Schema().Connection("hospital").HasTable("system_config_tables") {
		facades.Schema().Connection("hospital").Create("system_config_tables", func(table schema.Blueprint) {
			table.ID()
			table.String("field_name")
			table.String("field_type").Default("")
			table.String("input_type").Default("input")
			table.UnsignedBigInteger("system_config_tab_id").Default(0)
			table.String("parameter").Default("")
			table.SmallInteger("upload_type").Default(1)
			table.String("required").Default("")
			table.Integer("width")
			table.Integer("height")
			table.Text("value").Comment("设置值，或者默认值")
			table.String("info").Default("")
			table.String("description").Default("")
			table.Integer("sort").Default(0)
			table.SmallInteger("hidden").Default(0)
			table.SmallInteger("level").Default(0)
			table.Timestamps()
		})
	}
	return nil
}

// Down Reverse the migrations.
func (r *M20250303153232CreateSystemConfigTables) Down() error {
	facades.Schema().DropIfExists("system_config_tables")
	facades.Schema().Connection("school").DropIfExists("system_config_tables")
	facades.Schema().Connection("hospital").DropIfExists("system_config_tables")
	return nil
}
